package gdconf

import (
	"server_cluster/common/logger"
)

// 鱼竿配置表

type FishRodConfig struct {
	FishRodId int32    `csv:"ID" gorm:"primary_key;autoIncrement:false"` // 鱼竿id
	Effect    IntArray `csv:"Func,omitempty"`                            // 加成效果
}

func (f *FishRodConfig) TableName() string {
	return "config_fish_rod"
}

func (g *GameDataConfig) saveFishRodConfig() {
	saveTableToDb[FishRodConfig](g.Db, readTable[FishRodConfig](g.CsvPathPrefix+"FishingRod.csv"))
}

func (g *GameDataConfig) loadFishRodConfig() {
	g.GameDataMaps.FishRodConfigMap = make(map[int32]*FishRodConfig)
	for _, fishRodConfig := range loadTableFromDb[FishRodConfig](g.Db) {
		g.GameDataMaps.FishRodConfigMap[fishRodConfig.FishRodId] = fishRodConfig
	}
	logger.Info("FishRodConfig Count: %v", len(g.GameDataMaps.FishRodConfigMap))
}

func GetFishRodConfig(fishRodId int32) *FishRodConfig {
	value, exist := CONF.GameDataMaps.FishRodConfigMap[fishRodId]
	if !exist {
		logger.Error("[ConfigNotFound] FishRodConfig, fishRodId: %v", fishRodId)
		return nil
	}
	return value
}

func GetFishRodConfigMap() map[int32]*FishRodConfig {
	return CONF.GameDataMaps.FishRodConfigMap
}
